{include file='common/head'}
<div style="overflow-x: hidden;width: 96%;margin: auto;padding-top: 1rem;height: 750px">
    <div class="layui-form" action="" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 120px"><span style="color: red">*</span>一级分类</label>
            <div class="layui-input-inline" >
                <select name="cate_class_id" lay-verify="required" lay-search>
                    <option value="">选择所属一级分类</option>
                    {foreach $cate as $c}
                    <option value="{$c.id}" {if(isset($info.cate_class_id))}{if($info.cate_class_id == $c.id)}selected{/if}{/if}>{$c.cate_class}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 120px"><span style="color: red">*</span>二级分类名称</label>
            <div class="layui-input-inline">
                <input type="hidden" id="id" value="{$info.id | default= ''}">
                <input type="text" name="resource" value="{$info.resource |default=''}"  lay-verify="title" autocomplete="off" placeholder="请输入二级分类名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="width: 120px">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
            </div>
        </div>
    </div>
</div>
{include file='common/footer'}


<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('demo');

        //自定义验证规则
        form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function(data){
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });



        //监听提交
        form.on('submit(demo1)', function(data){
            var id = $('#id').val();
            data.field['id'] = id;
            $.ajax({
                url: '{:url("Order/cateAdd2")}',
                type: 'post',
                dataType: 'json',
                data: data.field,
                success: function (obj) {
                    if(obj.code==200){
                        parent.layer.msg(obj.msg);
                        //当你在iframe页面关闭自身时
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index,data.field); //再执行关闭
                    }
                    if(obj.code==400){
                        layer.msg(obj.msg, {icon: 5,time: 1000});
                    }
                },
                error:function(data){
                    console.log(data);
                }
            });

        });


    });
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload' //绑定元素
            ,url: '{:url("Upload/file_images")}' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.code == 200){
                    $('.img').attr('src',res.data.src)
                    $('.img_str').val(res.data.src);
                }
            }
            ,accept: ''
            ,error: function(res){
                //请求异常回调
                console.log(res)
            }
        });
    });
</script>

</body>
</html>